/*
 * @Author: Wangjun
 * @Date: 2023-08-03 09:51:03SetExtend
 * @LastEditTime: 2023-09-20 13:43:59
 * @LastEditors: Wangjun
 * @Description:
 * @FilePath: \nodex\nodetime\op_tadd.go
 * hnxr
 */
package nodetime

import (
	"gitee.com/hnxr_1/nodex"
)

func init() {
	nodex.Reister(new(TADD))
}

type TADD struct {
	nodex.Node
	X1 nodex.Double `remark:"时间"`
	X2 nodex.Double `remark:"秒数"`
	Y  nodex.Double `remark:"输出Y,,out"`
}

func (m *TADD) GetModelID() int {
	return nodex.ModTimer
}

/**
 * @description:
 * @return {*}
 */
func (m *TADD) GetName() string {
	return "TADD"
}
func (m *TADD) RegData() []byte {
	return nodex.MakeRegData(m, "时间加法", m.GetName(), "")
}

func (m *TADD) Calc() (err error) {
	if m.EnQ {
		if *m.X1.Bad || *m.X2.Bad {
			m.Bad = true
			return //不计算
		}
	}

	m.Bad = false
	hh := int(m.X1.Value) / 10000
	mm := (int(m.X1.Value) % 10000) / 100
	ss := int(m.X1.Value) % 100
	sec := hh*3600 + mm*60 + ss
	sec += int(m.X2.Value)

	hh = sec / 3600
	mm = (sec % 3600) / 60
	ss = sec % 60
	m.Y.Value = float64(hh*10000 + mm*100 + ss)
	return
}
